<template>
  <a-spin :spinning="loading">
    <a-form v-bind="formItemLayout">
      <a-row>
        <a-col :span="24">
          <a-form-item label=" 复查人员" v-bind="validateInfos.reviewPersonnel">
            <a-input v-model:value="formData.reviewPersonnel" placeholder="请输入 复查人员" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="复查时间" v-bind="validateInfos.reviewTime">
		        <a-date-picker placeholder="请选择复查时间"  v-model:value="formData.reviewTime" showTime value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="复查描述" v-bind="validateInfos.reviewDesc">
            <a-input v-model:value="formData.reviewDesc" placeholder="请输入复查描述" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="复查照片" v-bind="validateInfos.reviewPhoto">
	          <j-image-upload  v-model:value="formData.reviewPhoto" :disabled="disabled"></j-image-upload>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="复查状态" v-bind="validateInfos.status">
            <a-input v-model:value="formData.status" placeholder="请输入复查状态" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-spin>
</template>

<script lang="ts">
  import { defineComponent, ref, reactive, toRaw } from 'vue';
  import { queryZyReviewInformationListByMainId } from '../ZyHazardInvestigation.api';
  import JImageUpload from '/@/components/Form/src/jeecg/components/JImageUpload.vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { Form } from 'ant-design-vue';
  const useForm = Form.useForm;

  export default defineComponent({
    name: 'ZyReviewInformationForm',
    components:{
      JImageUpload,
    },
    props:{
      disabled:{
        type: Boolean,
        default: false
      }
    },
    setup(){
      const { createMessage } = useMessage();
      const isForm = true;
      const loading = ref(false);
      const formData = reactive<Record<string, any>>({
        id: '',
        reviewPersonnel: '',   
        reviewTime: '',   
        reviewDesc: '',   
        reviewPhoto: '',   
        status: '',   
      });
      //表单验证
      const validatorRules = reactive({
      })
      const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, {immediate: true});
      const formItemLayout = {
        labelCol: { xs: { span: 24 }, sm: { span: 5 } },
        wrapperCol: { xs: { span: 24 }, sm: { span: 16 } },
      };

      async function initFormData(mainId) {
        resetFields();
        if(mainId){
          let list = await queryZyReviewInformationListByMainId(mainId);
          if(list && list.length>0){
            let temp = list[0];
            Object.keys(temp).map(k=>{
              formData[k] = temp[k];
            })
          }
        }
      }

      async function getFormData() {
        await validate();
        let subFormData = toRaw(formData);
        if(Object.keys(subFormData).length>0){
          return subFormData
        }
        return false;
      }

      function setFieldsValue(values) {
        if(values){
          Object.keys(values).map(k=>{
            formData[k] = values[k];
          });
        }
      }

      /**
       * 值改变事件触发-树控件回调
       * @param key
       * @param value
       */
      function handleFormChange(key, value) {
        formData[key] = value;
      }


      return {
        loading,
        formData,
        formItemLayout,
        initFormData,
        getFormData,
        setFieldsValue,
        handleFormChange,
        isForm,
        validateInfos
      }
    }
  });
</script>
